package com.cloudcross.ssp.common.mail;

import java.util.Date;

import com.cloudcross.ssp.common.LoadConfig;

/**
 * 发送邮件 创建人：杜武強 创建时间：2016.04.07
 * 
 *
 */
public class SendMailUtil {

    /**
     * 
     * @param subject
     *            邮件主题
     * @param content
     *            邮件内容
     * @param toAddresstmp
     *            收件地址,多个收件人以“$$”分割
     */
    public synchronized static void sendMail(String subject, String content, String toAddresstmp) {
        MailSenderInfo mailInfo = new MailSenderInfo();

        String host = LoadConfig.getProperties("mail.smtp.host");
        String port = LoadConfig.getProperties("mail.smtp.port");
        String auth = LoadConfig.getProperties("mail.smtp.auth");
        String username = LoadConfig.getProperties("mail.smtp.username");
        String password = LoadConfig.getProperties("mail.smtp.password");
        String fromAddress = LoadConfig.getProperties("mail.smtp.fromAddress");

        mailInfo.setConnectiontimeout("10000");
        mailInfo.setTimeout("10000");
        mailInfo.setMailServerHost(host);
        mailInfo.setMailServerPort(port);
        mailInfo.setValidate(Boolean.parseBoolean(auth));
        // 邮箱用户名
        mailInfo.setUserName(username);
        // 邮箱密码
        mailInfo.setPassword(password);
        // 发件人邮箱
        mailInfo.setFromAddress(fromAddress);
        // 收件人邮箱
        String[] toAddress = toAddresstmp.split(",");
        mailInfo.setToAddress(toAddress);
        // 邮件标题
        mailInfo.setSubject(subject);
        // 邮件内容
        StringBuilder builder = new StringBuilder();
        builder.append(content);

        mailInfo.setContent(builder.toString());
        // 发送邮件
        MultipleMailSender sms = new MultipleMailSender();
        // 发送html格式
        sms.sendHtmlMail(mailInfo);
    }

    public static void main(String[] args) {
        SendMailUtil.sendMail("发送邮件测试", "ssp_web邮件提醒" + new Date(), "yongxing.bu@cloudcross.com");
    }
}
